package jc;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class JavaTest {
    // 泛型方法 printArray
    public static < E > void printArray( E[] inputArray )
    {
        // 输出数组元素
        for ( E element : inputArray ){
            System.out.printf( "%s ", element );
        }
        System.out.println();
    }
    public static <T> void printData(T data){
        System.out.println(data);
    }
    public static void main(String[] args) {
        // 创建不同类型数组： Integer, Double 和 Character
        Integer[] intArray = { 1, 2, 3, 4, 5 };
        Double[] doubleArray = { 1.1, 2.2, 3.3, 4.4 };
        Character[] charArray = { 'H', 'E', 'L', 'L', 'O' };

        System.out.println( "整型数组元素为:" );
        printArray( intArray  ); // 传递一个整型数组

        System.out.println( "\n双精度型数组元素为:" );
        printArray( doubleArray ); // 传递一个双精度型数组

        System.out.println( "\n字符型数组元素为:" );
        printArray( charArray ); // 传递一个字符型数组

        Calendar c1 = Calendar.getInstance();
// 获得年份
        int year = c1.get(Calendar.YEAR);
// 获得月份
        int month = c1.get(Calendar.MONTH) + 1;

        System.out.println("year ="+year+" month="+month);
        month = 2;
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        try {
//            int daysOfMonth = getDaysOfMonth(sdf.parse("2022-9-22"));
            int daysOfMonth = getDaysOfMonth(sdf.parse("2022-"+month));
            List<String> monthTime = getMonthTime(daysOfMonth, month);
            for (int i = 0; i < monthTime.size(); i++) {
                System.out.println(monthTime.get(i));
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }

    }
    public static List<String> getMonthTime(int data,int month){
        List<String> times =new ArrayList<>();
        for (int i = 1; i <= data; i++) {
            times.add(month+"-"+i);
        }
        return times;
    }

    public static int getDaysOfMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    }


}
